<template>
  <div class="mod-log">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.raw" style="width: 500px" placeholder="日志文本" clearable></el-input>
      </el-form-item>



      <el-form-item>
        <el-date-picker
          v-model="PayTime"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="支付时间从"
          end-placeholder="结束日期"
        >   <!--用change事件监听表单内容变化-->
        </el-date-picker>
      </el-form-item>



      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%">

      <el-table-column
        prop="hostname"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="主机名">
      </el-table-column>

      <el-table-column
        prop="logkit_send_time"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="logkit发送时间">
      </el-table-column>

      <el-table-column
        prop="datasource"
        header-align="center"
        align="center"
        width="350"
        :show-overflow-tooltip="true"
        label="数据源">
      </el-table-column>
      <el-table-column
        prop="raw"
        header-align="center"
        align="center"
        width="670"
        :show-overflow-tooltip="true"
        label="日志文本">
      </el-table-column>
      <el-table-column
        prop="_time"
        header-align="center"
        align="center"
        width="150"
        label="时间">
      </el-table-column>

      <el-table-column
        prop="localip"
        header-align="center"
        align="center"
        width="150"
        label="IP地址">
      </el-table-column>



    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      :dateChangebirthday1="1"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
// import vue from "vue";

// let cell;
export default {

  data () {
    return {
      dataForm: {
        raw: '',
        pay_time_Start: '',
        pay_time_End: ''

      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },

      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      selectionDataList: [],
      PayTime: ''
    }
  },

  created () {
    this.getDataList()
  },

  methods: {
    // 获取数据列表
    getDataList () {
      let startTime = this.dataForm.pay_time_Start = this.PayTime[0]
      let endTime = this.dataForm.pay_time_End = this.PayTime[1]
      if (startTime == null || endTime == null) {
        startTime = ''
        endTime = ''
      }
      this.dataListLoading = true

      this.$http({
        url: this.$http.adornUrl('/multiSearch/log/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'username': this.dataForm.userName,
          'raw': this.dataForm.raw,
          'startTime': startTime,
          'endTime': endTime
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>
